home *** CD-ROM | disk | FTP | other *** search
/ Merciful 2 / Merciful - Disc 2.iso / software / i / ian'simagineutilsv1.3.lha / IIUtilities / StageLengthen < prev    next >
Text File  |  1995-01-14  |  4KB  |  101 lines

  1. /*\
  2.  *  StageLengthen can add frames to an animation and extend the actor
  3.  *  bars automaticly.  This is for when you want to add another scene
  4.  *  to an animation and don't wnat to edit 50 actor bars by hand when
  5.  *  you add more frames.
  6.  *
  7.  *  Usage: StageLengthen <stageFileName> <newFrames> <lengthenThreshold>
  8.  *    stageFileName is renamed to stageFileName.old for backup.
  9.  *    NewFrames is how many frames to add to the animation.  You can set
  10.  *    this to zero to not add any frames.
  11.  *    LengthenThreshold is how close can the actor bar be to the end of
  12.  *    the animation before it gets expanded.  Using a paramter of 0 here
  13.  *    would only expand an actor if it was in the last frame.  A 1 would
  14.  *    lengthen bars that were 1 frame away from the end, and a 10000
  15.  *    would lengthen every actor.
  16.  *
  17.  *  Notes:
  18.  *    Each object is given a line of its own in the output.  A "." is
  19.  *    displayed for each timeline bar that is modified.
  20.  *    If you want to stretch the entire animation to fill the new size,
  21.  *    use StageFrames instead.  This is for adding a new scene.
  22.  *    Globals, Lights, objects, and the Camera actor bar are the only
  23.  *    bars that are changed.  Line 78 has a list of every IFF HUNK that
  24.  *    this script will modify.
  25.  *
  26.  *  V1.0 Jan-14-94
  27.  *  IanSmith@moose.erie.net
  28.  *
  29. \*/
  30.  
  31. Numeric Digits 14                    /* Need at least 12 to handle 32 bits */
  32. Parse Arg FileName Change Threshold .
  33. If Threshold="" Then Do
  34.  Say "Usage: StageLengthen <stageFileName> <newFrames> <lengthenThreshold>"
  35.  Say "       More help can be found in the header of this ARexx file."
  36.  Exit
  37. End
  38.  
  39. MaxFrames=0
  40. Temp="Temp$Stage."||Date(D)||Time(S)               /* Create temp filename */
  41. Address Command 'Delete >NIL:' FileName||".Old"    /* Erase backup file */
  42. If Open(Out,Temp,"W")=0 Then Do
  43.  Say "Can't open temp staging file!"
  44.  Exit
  45. End
  46. If Open(In,FileName,"R")=0 Then Do
  47.  Say "Can't find '"FileName"' to open!"
  48.  Exit
  49. End
  50. Call Open(Text,"*","W")
  51. Call WriteCH(Text,"Shifting '"||FileName||"' forward "||Change||" frames.")
  52. Call ParseStaging(C2D(SubStr(ReadWrite(In,12),5,4)))
  53. Call WriteLN(Text,"") Close(In) Close(Out) Close(Text)
  54. Address Command 'Rename' FileName 'To' FileName||".Old"
  55. Address Command 'Rename' Temp 'To' FileName
  56.  
  57. Exit
  58.  
  59. ParseStaging: PROCEDURE EXPOSE Change Threshold MaxFrames
  60.  Parse Arg MaxSize                             /* Recursive Function     */
  61.  TotalSize=4; New=0
  62.  Do Until TotalSize>=MaxSize                   /* Read MaxSize Bytes     */
  63.   LastName=Name
  64.   Name=ReadWrite(In,4)
  65.   If Name~=LastName Then New=0
  66.   Size=C2D(ReadWrite(In,4))
  67.   If Size//2=1 Then Size=Size+1                /* Add pad byte if needed */
  68.   If Name="ISTG" | Name="SOBJ" Then Do
  69.    TotalSize=TotalSize+ParseStaging(Size)+8    /* Parse into these hunks */
  70.    Iterate
  71.   End
  72.   TotalSize=TotalSize+Size+8                   /* Add SIZE and NAME length */
  73.   If Name="NAME" Then
  74.    Call WriteCH(Text,'0A'x||"  "||ReadWrite(In,Size))
  75.   Else If Name="MAXF" Then Do
  76.    MaxFrames=C2D(ReadCH(In,Size))
  77.    Call WriteCH(Out,Right(D2C(MaxFrames+Change),2,'00'x))
  78.   End; Else If Index("FIL3-LIT2-GLB3-CAMR", Name)~=0 Then Do
  79.    Buffer=ReadCH(In,Size)
  80.    StartF=C2D(SubStr(Buffer,3,2))
  81.    EndF=C2D(SubStr(Buffer,5,2))
  82.    If (StartF>0 & StartF<=MaxFrames & EndF>0 & EndF<=MaxFrames & StartF<=EndF) Then Do
  83.     If (MaxFrames-EndF)<=Threshold Then Do
  84.      Call WriteCH(Text,".")
  85.      Buffer=Overlay(Right(D2C(MaxFrames+Change),2,'00'x),Buffer,5)
  86.     End
  87.    End; Else Do
  88.     Say "Hunk" Name "is not a valid timeline!"
  89.    End
  90.    Call WriteCH(Out,Buffer)
  91.   End; Else
  92.    Call ReadWrite(In,Size)
  93.  End
  94. Return TotalSize
  95.  
  96. ReadWrite:
  97.  Parse Arg FileHandle , Bytes .
  98.  RWBuffer=ReadCH(FileHandle, Bytes)
  99.  Call WriteCH(Out,RWBuffer)
  100. Return RWBuffer
  101.